<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Swoole\Http\Server class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="swoole-http-response.write.html">« Swoole\Http\Response::write</a></li>
      <li style="float: right;"><a href="swoole-http-server.on.html">Swoole\Http\Server::on »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.swoole.html">Swoole</a></li>
    <li>The Swoole\Http\Server class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.swoole-http-server" class="reference">

 <h1 class="title">The Swoole\Http\Server class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL swoole &gt;= 1.9.0)</p>


  <div class="section" id="swoole-http-server.intro">
   <h2 class="title">简介</h2>
   <p class="para">

   </p>
  </div>


  <div class="section" id="swoole-http-server.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Swoole\Http\Server</strong>
     </span>
     
     <span class="ooclass">
      <span class="modifier">extends</span>
       <a href="class.swoole-server.html" class="classname">Swoole\Server</a>
     </span>
     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="swoole-http-server.on.html" class="methodname">on</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-http-server.start.html" class="methodname">start</a></span>(): <span class="type"><span class="type void">void</span></span></div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.addlistener.html" class="methodname">Swoole\Server::addlistener</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$socket_type</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.addprocess.html" class="methodname">Swoole\Server::addProcess</a></span>(<span class="methodparam"><span class="type"><a href="class.swoole-process.html" class="type swoole_process">swoole_process</a></span> <code class="parameter">$process</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.after.html" class="methodname">Swoole\Server::after</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$after_time_ms</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$param</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type ReturnType">ReturnType</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.bind.html" class="methodname">Swoole\Server::bind</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$uid</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.cleartimer.html" class="methodname">Swoole\Server::clearTimer</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$timer_id</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>swoole_timer_clear</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$timer_id</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.close.html" class="methodname">Swoole\Server::close</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$reset</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.confirm.html" class="methodname">Swoole\Server::confirm</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.connection-info.html" class="methodname">Swoole\Server::connection_info</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$reactor_id</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.connection-list.html" class="methodname">Swoole\Server::connection_list</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$start_fd</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$pagesize</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.defer.html" class="methodname">Swoole\Server::defer</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server-port.destruct.html" class="methodname">Swoole\Server\Port::__destruct</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server-port.on.html" class="methodname">Swoole\Server\Port::on</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type ReturnType">ReturnType</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server-port.set.html" class="methodname">Swoole\Server\Port::set</a></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$settings</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.exist.html" class="methodname">Swoole\Server::exist</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.finish.html" class="methodname">Swoole\Server::finish</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.getclientinfo.html" class="methodname">Swoole\Server::getClientInfo</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$reactor_id</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$ignore_error</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.getclientlist.html" class="methodname">Swoole\Server::getClientList</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$start_fd</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$pagesize</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.getlasterror.html" class="methodname">Swoole\Server::getLastError</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.heartbeat.html" class="methodname">Swoole\Server::heartbeat</a></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$if_close_connection</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.listen.html" class="methodname">Swoole\Server::listen</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$socket_type</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.on.html" class="methodname">Swoole\Server::on</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.pause.html" class="methodname">Swoole\Server::pause</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.protect.html" class="methodname">Swoole\Server::protect</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_protected</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.reload.html" class="methodname">Swoole\Server::reload</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.resume.html" class="methodname">Swoole\Server::resume</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.send.html" class="methodname">Swoole\Server::send</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$reactor_id</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.sendfile.html" class="methodname">Swoole\Server::sendfile</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.sendmessage.html" class="methodname">Swoole\Server::sendMessage</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$worker_id</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.sendto.html" class="methodname">Swoole\Server::sendto</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$ip</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$server_socket</code><span class="initializer"> = ?</span></span><br>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.sendwait.html" class="methodname">Swoole\Server::sendwait</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.set.html" class="methodname">Swoole\Server::set</a></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$settings</code></span>): <span class="type"><span class="type ReturnType">ReturnType</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.shutdown.html" class="methodname">Swoole\Server::shutdown</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.start.html" class="methodname">Swoole\Server::start</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.stats.html" class="methodname">Swoole\Server::stats</a></span>(): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.stop.html" class="methodname">Swoole\Server::stop</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$worker_id</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.task.html" class="methodname">Swoole\Server::task</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_worker_id</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.taskwait.html" class="methodname">Swoole\Server::taskwait</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">float</span> <code class="parameter">$timeout</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$worker_id</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.taskwaitmulti.html" class="methodname">Swoole\Server::taskWaitMulti</a></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$tasks</code></span>, <span class="methodparam"><span class="type">float</span> <code class="parameter">$timeout_ms</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="swoole-server.tick.html" class="methodname">Swoole\Server::tick</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$interval_ms</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type void">void</span></span></div>


   }</div>


  </div>

 </div>

 















<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="swoole-http-server.on.html">Swoole\Http\Server::on</a> — Bind callback function to HTTP server by event name.</li><li><a href="swoole-http-server.start.html">Swoole\Http\Server::start</a> — Start the swoole http server.</li></ul>
</div>
</div></div></body></html>